package com.github.zxhtom.excel.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

/**
 * 数字类工具
 * 
 * @author zxhtom
 * @date 2018年8月21日
 * @since 1.0
 */
public class MathUtil {
	private static MathUtil mathUtil;

	private MathUtil() {
	}

	public static MathUtil getInstance() {
		if (mathUtil == null) {
			mathUtil = new MathUtil();
		}
		return mathUtil;
	}

	/**
	 * [min,max]
	 * @param min
	 * @param max
	 * @return
	 */
	public Integer getRandom(Integer min , Integer max){
		return (int)(min+Math.random()*(max-min+1)); //从1到10的int型随数
	}

	/**
	 * 根据比例 ， 筛选出数据
	 * @param calc
	 * @param objArr
	 * @return
	 */
	public Object getRandByChange(Double[] calc, Object[] objArr) {
		List<Double> randomList = Arrays.asList(calc);
		LotteryUtil ll = new LotteryUtil(randomList);
		int index = ll.randomColunmIndex();
		if (index < objArr.length) {
			return objArr[index];
		}
		return null;
	}
	public Integer getNumByRand(Double calc, Integer num) {
		List<Double> randomList = new ArrayList<>();
		randomList.add(10000 * calc);
		randomList.add(10000 - 10000 * calc);
		LotteryUtil ll = new LotteryUtil(randomList);
		int index = ll.randomColunmIndex();
		if (index == 0) {
			return num;
		}
		/*Integer random = getRandom(0, 10000);
        if (DoubleUtil.getInstance().sub(Double.valueOf(random), 100000 * calc) <= 0) {
            return num;
        }*/
        return 0;
    }

	public static String game(int count){
		StringBuffer sb = new StringBuffer();
		String str = "0123456789";
		Random r = new Random();
		for(int i=0;i<count;i++){
			int num = r.nextInt(str.length());
			sb.append(str.charAt(num));
			str = str.replace((str.charAt(num)+""), "");
		}
		return sb.toString();
	}
}
